package com.example.current.futrue;

import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class FutrueExmaple1 {
    static class MyCallable implements Callable<String>{
        String msg;
        public MyCallable(String msg){
            this.msg=msg;
        }
        @Override
        public String call() throws Exception {
            System.out.println("进入线程CALLBACK");
            Thread.sleep(1);
            if(1 == 1){
                throw new RuntimeException("我是异常");
            }
            return msg;
        }
    }

    public static void main(String[] args) throws Exception {
        ThreadLocal<Object> objectThreadLocal = new ThreadLocal<>();
        objectThreadLocal.get();
        ConcurrentHashMap<Object, Object> map = new ConcurrentHashMap<>();

        map.put("","");
        ExecutorService executorService = Executors.newCachedThreadPool();
        Future<String> submit = executorService.submit(new MyCallable("yyj"));
        System.out.println("do other");
        Thread.sleep(1);
        try {
            String s = submit.get();
            System.out.println(s);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("do end");
        executorService.shutdown();
        Object o = new Object();
        o.wait();
    }
}
